var $alert = {};
$alert.stopBodyScroll = function(isFixed, that) {
	var bodyEl = document.body;
	if (isFixed) { //开启
		that._top = window.scrollY;
		bodyEl.style.position = 'fixed';
		bodyEl.style.top = -that._top + 'px';
	} else { //关闭
		bodyEl.style.position = 'relative';
		bodyEl.style.top = '';
		window.scrollTo(0, that._top); // 回到原先的top
	}
};
/**
 *  param
 *  
 *  text : '内容'
 * 
 *  isCancel: true/false 是否展示取消
 *  
 *  confirm 确认回调
 * 
 * 	cancel  取消回调
 * 
 * */

$alert.show = function(param) {
	this.alertMask = document.getElementById("alert-mask");
	this.stopBodyScroll(true, this);
  var text = param ? param.text || '' : ''
  var isCancel = param ? param.isCancel : false
	if (this.alertMask) {
		var dom = document.getElementById("alert-text");
		dom.innerHTML = text
		this.alertMask.style.display = "block";
	} else {
		this.alert = document.createElement("div");
		this.htmlCancel = '<div id="alert-mask" class="alert-mask"><div><div class="alert-inner"><div class="alert-title">提示</div><div id="alert-text" class="alert-text">'+ text +'</div></div><div class="alert-buttons"><div id="alert-then" class="alert-button alert-then">确定</div><div id="alert-catch" class="alert-button alert-catch">取消</div></div></div></div>'
		this.html = '<div id="alert-mask" class="alert-mask"><div><div class="alert-inner"><div class="alert-title">提示</div><div id="alert-text" class="alert-text">'+ text +'</div></div><div class="alert-buttons"><div id="alert-then" class="alert-button alert-then">确定</div></div></div></div>'
		this.alert.innerHTML = isCancel ? this.htmlCancel : this.html;
		document.body.appendChild(this.alert);
	};
	var alertThen = document.getElementById('alert-then');
	var alertCatch = document.getElementById('alert-catch');
	alertThen.onclick = function(){
		$alert.hide()
		param && param.confirm && param.confirm()
	}
	if(alertCatch) {
		alertCatch.onclick = function(){
			$alert.hide()
			param && param.cancel && param.cancel()
		}
	}
};
$alert.hide = function() {
	this.stopBodyScroll(false, this);
	try {
		this.alertMask = document.getElementById("alert-mask");
		this.alertMask.style.display = "none";
	} catch (e) {};
};
